package com.tduck.cloud.datav.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tduck.cloud.common.util.QueryWrapperUtils;
import com.tduck.cloud.common.util.Result;
import com.tduck.cloud.common.util.SecurityUtils;
import com.tduck.cloud.datav.entity.ScreenGroupEntity;
import com.tduck.cloud.datav.service.ScreenGroupService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 数据大屏分组
 *
 * @author tduck-gen
 * @since  2022-02-20 13:44:13
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/datav/screen/group")
public class ScreenGroupController {
    private final ScreenGroupService screenGroupService;


    /**
     * 查询数据大屏用户项目分组列表
     */
    @GetMapping("/list")
    public Result queryList() {
        return Result.success(screenGroupService.list());
    }

    /**
     * 查询数据大屏用户项目分组列表
     */
    @GetMapping("/page")
    public Result queryPage(ScreenGroupEntity group, Page page) {
        return Result.success(screenGroupService.page(page, QueryWrapperUtils.toSimpleQuery(group)));
    }

    /**
     * 获取数据大屏用户项目分组详细信息
     */
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id) {
        return Result.success(screenGroupService.getById(id));
    }

    /**
     * 新增数据大屏用户项目分组
     */
    @PostMapping("save")
    public Result save(@RequestBody ScreenGroupEntity userProjectGroup) {
        userProjectGroup.setUserId(SecurityUtils.getUserId());
        return Result.success(screenGroupService.save(userProjectGroup));
    }

    /**
     * 修改数据大屏用户项目分组
     */
    @PostMapping("update")
    public Result update(@RequestBody ScreenGroupEntity userProjectGroup) {
        return Result.success(screenGroupService.updateById(userProjectGroup));
    }

    /**
     * 删除数据大屏用户项目分组
     */
    @PostMapping("/delete/{id}")
    public Result delete(@PathVariable Long id) {
        return Result.success(screenGroupService.removeById(id));
    }
}
